package com.arrays;

public class MinimumSizeSubarraySum0125_209 {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0, right = 0;
        Long sum = 0L;
        int res = nums.length+1;
        for(right = 0; right<nums.length; right++){
            sum += nums[right];
            while (sum >= target){
                res = Math.min(res,right-left+1);
                sum -= nums[left];
                left++;
            }
        }
        if(sum < target && right - left == nums.length) res = 0;
        return res;
    }
}
